草庐IT

android - String转Android JSONObject丢失utf-8

全部标签

c# - 使用 .NET 如何将包含 Latin-1 重音字符的 ISO 8859-1 编码文本文件转换为 UTF-8

我正在发送保存在ISO88591-1中的文本文件包含来自Latin-1范围的重音字符(以及正常的ASCIIa-z等)的格式。如何将这些文件转换为UTF-8使用C#以便ISO8859-1中的单字节重音字符成为有效的UTF-8字符?我尝试使用带有ASCIIEncoding的StreamReader,然后通过实例化编码ascii和编码utf8然后使用将ASCII字符串转换为UTF-8Encoding.Convert(ascii,utf8,ascii.GetBytes(asciiString))—但重音字符呈现为问号。我错过了什么步骤? 最佳答案

C# Linq - 无法将 IEnumerable<string> 隐式转换为 List<string>

我有一个这样定义的列表:publicListAttachmentURLS;我正在像这样向列表中添加项目:instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment));但我收到此错误:无法将IEnumerable隐式转换为列表我做错了什么? 最佳答案 Where方法返回IEnumerable.尝试添加.ToLis

c# - 如何将 XML 转换为 List<string> 或 String[]?

如何将以下XML转换为List或String[]:12 最佳答案 听起来您更多的是在解析之后而不是完整的XML序列化/反序列化。如果您可以使用LINQtoXML,这将非常简单:usingSystem;usingSystem.Linq;usingSystem.Xml.Linq;publicclassTest{staticvoidMain(){stringxml="12";XDocumentdoc=XDocument.Parse(xml);varlist=doc.Root.Elements("id").Select(element=>e

c# - 如何将 string[] 转换为 ArrayList?

我有一个字符串数组。如何将其转换为System.Collections.ArrayList? 最佳答案 string[]myStringArray=newstring[2];myStringArray[0]="G";myStringArray[1]="L";ArrayListmyArrayList=newArrayList();myArrayList.AddRange(myStringArray); 关于c#-如何将string[]转换为ArrayList?,我们在StackOverfl

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

好吧,我放弃了,你如何在一行中做到这一点?publicobjectConvert(object[]values,TypetargetType,objectparameter,System.Globalization.CultureInfoculture){//Listfields=values.ToList();//Listfields=valuesasList;//Listfields=(List)values;Listfields=newList();foreach(objectvalueinvalues){fields.Add(value.ToString());}//proce

c# - 哪种机制是扩展 Dictionary 以处理丢失键的更好方法,为什么?

我发现自己经常遇到一个小烦恼-我有一个Dictionary包含可能存在或不存在的值。所以正常的行为是使用索引器,像这样:objectresult=myDictionary["key"];但是,如果"key"不在字典中这会抛出KeyNotFoundException,所以你改为这样做:objectval;if(!myDictionary.TryGetValue("key",outval)){val=ifNotFound;}这很好,除了我可以连续加载这些-TryGetValue开始觉得笨重得要命。所以选项1是一种扩展方法:publicstaticTValueTryGet(thisDicti

c# - 这段代码怎么可能: "ArgumentOutOfRangeException: startIndex cannot be larger than length of string"?

我的C#代码中有以下方法://////Removesthefirst(leftmost)occurenceofafroma.//////Thestringtoremovethefrom.Cannotbenull.///Thesubstringtolookforandremovefromthe.Cannotbenull.//////Therestofthe,afterthefirst(leftmost)occurenceoftheinit(ifany)hasbeenremoved.////////////Ifthedoesnotoccurwithinthe,theisreturnedin

c# - String.GetHashCode() 返回不同的值

为什么GetHashCode()为同一个字符串返回不同的值?我无法描述如何复制它,但请相信这不是一个恶作剧,并且以下两行来self的watch窗口在两个不同的时间:"DDD.Events.Application.ApplicationReferenceCreated".GetHashCode()-1386151123int"DDD.Events.Application.ApplicationReferenceCreated".GetHashCode()1858139950int怎么会这样?我不知道这是否有帮助,但我在VS2010中运行.NET4.0,并且正在调试NServiceBus应

c# - Autofixture:控制创建的 string[] 类型元素的数量

我在创建类型为string[]的字符串数组时遇到问题,每次它都会创建3个值,但我希望能够控制它。我正在使用vartst=fixture.Create();我也研究过使用CreateMany但它似乎返回了一种IEnumerable。有人有什么想法吗? 最佳答案 使用RepeatCount属性:varfixture=newFixture{RepeatCount=9};varactual=fixture.Create();//->The'actual'arrayis9itemsnow.或fixture.CreateMany(9).ToAr

c# - 将 List<KeyValuePair<string, string>> 序列化为 JSON

我是JSON的新手,请帮忙!我正在尝试序列化List>作为JSON目前:[{"Key":"MyKey1","Value":"MyValue1"},{"Key":"MyKey2","Value":"MyValue2"}]预期:[{"MyKey1":"MyValue1"},{"MyKey2":"MyValue2"}]我引用了this中的一些示例和this.这是我的KeyValuePairJsonConverter:JsonConverterpublicclassKeyValuePairJsonConverter:JsonConverter{publicoverridevoidWriteJs